// @ts-nocheck
// eslint-disable-next-line prefer-const

import { default as _get } from 'lodash/get'
import cornerstoneTools from "cornerstone-tools"

// 自动播放开关
export let playSwitch = false

// 分屏联动播放开关
export let LinkageSwitch = true


export const currPlayPos = [];

// modality

export let currModality = { modality: 'CT' }

// 分屏内元素信息
// {playCurr:0 //当前播放位置,image //当前image  ,element // 当前dom元素, viewport //当前viewport 信息, series:{ instanceList } // 当前image所有影像, dicomType: '' // LOCALIZER 竖切面    }
export let LayerWindows = []

// 子分屏是否被拆分
export let SplitWindows = [];

// 是否子分屏最大化
// export let isSubViewPort = false;

// 分屏器

export const partScreen = {
  one: '1x1',
  two: '1x2',
  three: '1x3',
  four: '1x4',
  five: '2x1',
  six: '2x2',
  seven: '2x3',
  eight: '2x4',
  nine: '3x1',
  ten: '3x2',
  eleven: '3x3',
  twelve: '4x1',
  thirteen: '4x2',
}

export const screenTable = {
  one: { row: 1, col: 1 },
  two: { row: 1, col: 2 },
  three: { row: 1, col: 3 },
  four: { row: 1, col: 4 },
  five: { row: 2, col: 1 },
  six: { row: 2, col: 2 },
  seven: { row: 2, col: 3 },
  eight: { row: 2, col: 4 },
  nine: { row: 3, col: 1 },
  ten: { row: 3, col: 2 },
  eleven: { row: 3, col: 3 },
  twelve: { row: 4, col: 1 },
  thirteen: { row: 4, col: 2 }
}

// mpr 是否滚动
export const MRPINFO = {
  MPRISWHEEL: true,
  getVal(key) {
    return this[key]
  },
  setVal(key, val) {
    this[key] = val;
  }
};

// 当前滚动index
export let currRollInxObj = {
  currRollInx: 1
}

// 是否播放
export let relevance = {
  linkPlaying: true,
  currPlayIndex: -1
}

export let currTool = {
  curr: 'Zoom'
}

export function resetConfig(flag) {
  if (!flag) {
    currTool = {
      curr: 'Zoom'
    }
  }
  currRollInxObj = {
    currRollInx: 1
  }
  relevance = {
    linkPlaying: true,
    currPlayIndex: -1
  }
  SplitWindows = [];
  LayerWindows = []
}

// 重新注入基础工具
export function reInjectTools(flag) {
  setTimeout(() => {
    try {
      cornerstoneTools.setToolActive('StackScrollMouseWheel', {})
      cornerstoneTools.setToolActive('Overlay')
      // cornerstoneTools.setToolActive('ScaleOverlay')
      if(flag){
        cornerstoneTools.setToolActive(currTool.curr, {
          mouseButtonMask: 1
        })
      }
    } catch (error) {

    }
  })
}

export const synchronizer = new cornerstoneTools.Synchronizer(
  // Cornerstone event that should trigger synchronizer
  "cornerstonenewimage",
  // "cornerstoneimagerendered",
  // Logic that should run on target elements when event is observed on source elements
  // eslint-disable-next-line no-undef
  cornerstoneTools.updateImageSynchronizer,
)
//wwwc syn
export const wwwcSynchronizer = new cornerstoneTools.Synchronizer(
  'cornerstonetoolsmousedrag',
  cornerstoneTools.wwwcSynchronizer
)